package com.carrental.api.index;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.carrental.api.cms.domain.CmsCar;
import com.carrental.api.cms.service.ICmsCarService;
import com.carrental.api.common.query.CommonQueryParam;
import com.carrental.api.pms.domain.PmsStore;
import com.carrental.api.pms.domain.vo.PmsStoreVo;
import com.carrental.api.pms.service.IPmsStoreService;
import com.carrental.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author LiangYi
 * @since 2022/5/6 14:56
 */
@RequestMapping("/index")
@RestController
public class IndexController {
    @Autowired
    private ICmsCarService cmsCarService;
    @Autowired
    private IPmsStoreService pmsStoreService;

    @GetMapping("/getAllBannerList")
    public CommonResult<List<String>> getBannerList() {
        List<CmsCar> cmsCars = cmsCarService.list();
        List<String> carImages = cmsCars.stream().map(CmsCar::getCarImageUrl).collect(Collectors.toList());
        return CommonResult.success(carImages);
    }

    @GetMapping("/getStoreList")
    public CommonResult<List<PmsStore>> getStoreList(@RequestParam(required = false) String cityName, @RequestParam(required = false) String storeName) {
        List<PmsStore> storeList = pmsStoreService.list(
            new QueryWrapper<PmsStore>().lambda()
                .like(cityName != null, PmsStore::getAddress, cityName)
                .like(storeName != null, PmsStore::getStoreName, storeName)
                .eq(PmsStore::getIsEnabled, true)
                .eq(PmsStore::getIsDeleted, false)
        );
        return CommonResult.success(storeList);
    }
}
